package com.wchat.network.message.share;

import java.io.File;
import java.io.Serializable;

import org.simpleframework.xml.Element;

import com.wchat.network.message.file.FileInfo;

@Element
public class ShareItem implements Serializable {

	private static final long serialVersionUID = -8902329103720943690L;
	
	@Element
	public FileInfo fileInfo = new FileInfo();
	
	private ShareItem() {
		
	}
	
	public static ShareItem createShareItem(File file) {
		ShareItem item = new ShareItem();
		item.fileInfo.path = file.getAbsolutePath();
		item.fileInfo.fileName = file.getName();
		item.fileInfo.size = file.length();
		return item;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((fileInfo == null) ? 0 : fileInfo.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ShareItem other = (ShareItem) obj;
		if (fileInfo == null) {
			if (other.fileInfo != null)
				return false;
		} else if (!fileInfo.equals(other.fileInfo))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "ShareItem [fileInfo=" + fileInfo + "]";
	}
	
}
